package com.xxgc.helloword.util;

import com.xxgc.helloword.scheduler.QuartzScheduler;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Timer;
import java.util.TimerTask;
@RunWith(SpringRunner.class)
@SpringBootTest
public class TimerDemo {
    @Autowired
    QuartzScheduler quartzScheduler;

    @Test
    public void teest() throws InterruptedException {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("干饭了！干饭了！干饭了！");
            }
        },1000,5000);//延迟一秒后每隔五秒执行一次
        Thread.sleep(500000);
    }

    @Test
    public void test1() throws SchedulerException, InterruptedException {
        //2022年3月8日20时30分0秒开始 每五秒执行一次 cron表达式
        //0 0 6 1 3,6,9,12 ? *  每个月的3月6月9月12月的一号早上六点执行
        quartzScheduler.add(1,"0/5 30 20 8 3 ? 2022");
        Thread.sleep(500000);
    }
}
